<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抽签工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
        }
        input[type="file"] {
            margin-bottom: 20px;
        }
        #result {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ccc;
            min-height: 50px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>抽签工具</h1>
        <input type="file" id="fileInput" accept=".txt,.csv">
        <button onclick="draw()">开始抽签</button>
        <div id="result"></div>
    </div>
    <script>
        let names = [];

        document.getElementById('fileInput').addEventListener('change', function(event) {
            const file = event.target.files[0];
            const reader = new FileReader();
            reader.onload = function(e) {
                names = e.target.result.split(/\r?\n/).filter(name => name.trim() !== '');
            };
            reader.readAsText(file);
        });

        function draw() {
            if (names.length === 0) {
                alert('请先上传名单文件！');
                return;
            }
            const randomIndex = Math.floor(Math.random() * names.length);
            document.getElementById('result').innerText = '中签者：' + names[randomIndex];
        }
    </script>
</body>
</html>